//
//  GYSystemMsg.m
//  GoodLuck
//
//  Created by apple on 2018/3/20.
//  Copyright © 2018年 yunjiazhineng. All rights reserved.
//

#import "GYSystemMsg.h"
#import "GYNetWorkTools.h"

@implementation GYSystemMsg

+ (void)loadSystemMessage:(void (^)(NSArray * _Nullable, NSError * _Nullable))finish {
    [EasyLodingView showLodingText:@"正在加载..." config:^EasyLodingConfig *{
        EasyLodingConfig *config = [EasyLodingConfig shared];
        config.showOnWindow = YES;
        config.superReceiveEvent = NO;
        
        return config;
    }];
    [GYNetWorkTools requestSystemMessage:^(NSDictionary *obj) {
        int code = [[obj objectForKey:@"code"] intValue];
        NSDictionary *datas = [obj objectForKey:@"datas"];
        if (code == 200) {
            [EasyLodingView hidenLoingInView:[UIApplication sharedApplication].keyWindow];
            NSMutableArray *models = [NSMutableArray array];
            if ([[datas objectForKey:@"list"] isKindOfClass:[NSArray class]]) {
                NSArray *list = [datas objectForKey:@"list"];
                for (NSDictionary *dic in list) {
                    GYSystemMsg *model = [[GYSystemMsg alloc] initWithDic:dic];
                    [models addObject:model];
                }
                finish(models,nil);
            }else {
                finish(models,nil);
            }
        }else if (code == 400) {
            [EasyLodingView hidenLoingInView:[UIApplication sharedApplication].keyWindow];
            [EasyTextView showText:@"加载数据出错,请重新加载!"];
        }
    } error:^(NSError *error) {
        [EasyLodingView hidenLoingInView:[UIApplication sharedApplication].keyWindow];
        [EasyTextView showText:@"加载数据出错,请重新加载!"];
        NSLog(@"loadSystemMessageFailed===%@",error);
        finish(nil,error);
    }];
}


- (instancetype)initWithDic:(NSDictionary *)dic {
    if ([super init]) {
        [self setValuesForKeysWithDictionary:dic];
    }
    return  self;
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
    
}
@end
